"""知识页面"""
from selenium.webdriver.common.by import By
from page.base_page import BasePage
from selenium.webdriver.support.select import Select
class KnowledgePage(BasePage):
    """数据准备"""
    url="/index.php?m=knowledge"
    #定位器
    add_knowledge_locator = (By.LINK_TEXT, "添加知识")
    title_locator = (By.NAME, "title")
    btn_class_locator = (By.NAME, "category_id")
    content_locator = (By.CSS_SELECTOR, "body")
    click_save_locator = (By.CSS_SELECTOR,"body > div.container > div.row > div > form > table > tfoot > tr > td > input:nth-child(1)")
    accounts_receivable_name_locator=(By.CSS_SELECTOR,"body > div.container > div.alert.alert-success")
    clean_up_the_environment_locator=(By.CSS_SELECTOR,"#form1 > table > tbody > tr:nth-child(1) > td:nth-child(1) > input")
    delet_locator=(By.ID,"delete")
    click_return_locator=(By.CSS_SELECTOR,"body > div.container > div.row > div > form > table > tfoot > tr > td > input:nth-child(3)")
    def click_add_knowledge(self):
        """点击添加知识"""
        self.click(self.add_knowledge_locator)
    def title(self,content):
        """编辑标题"""
        self.send_keys(self.title_locator,content)
    def btn_class(self):
        """下拉框选择第一个"""
        self.seleect = Select(self.find_element(self.btn_class_locator))
        self.seleect.select_by_index(0)
    def content(self,content):
        """编辑内容"""
        #切换标题页面
        self.driver.switch_to.frame(0)
        # 编辑标题页面
        self.send_keys(self.content_locator,content)
        # 返回上一个页面
        self.driver.switch_to.parent_frame()
    def click_save(self):
        """点击保存"""
        self.click(self.click_save_locator)
    def accounts_article_name(self):
        """提取文章添加成功文本"""
        return self.find_element(self.accounts_receivable_name_locator).text
    def click_one_data(self):
        """选择第一条数据"""
        self.click(self.clean_up_the_environment_locator)
    def click_delete(self):
        """点击删除"""
        self.click(self.delet_locator)
    def click_sure(self):
        """弹出弹窗点击确定"""
        self.driver.switch_to.alert.accept()
    def click_return(self):
        """点击返回"""
        self.click(self.click_return_locator)





